//
//  MainPositionView.swift
//  MakeMoney
//
//  Created by Fan ZhiQiang on 2025/4/8.
//

import SwiftUI

struct MainPositionView: View {
    @State private var selectNum = 1
    @State private var lottery = total.first
    @Bindable var pathStore: PathStore
    let columns = [GridItem(.fixed(50), spacing: 20)]
    
    
    var body: some View {
        List {
            Section("前区") {
                LazyHGrid(rows: columns, spacing: 15) {
                    ForEach(1..<6) { num in
                        Button {
                            selectNum = num
                        } label: {
                            Text("\(num)")
                                .font(.title)
                                .foregroundStyle(.white)
                                .frame(minWidth: 50, idealWidth: 50, maxWidth: 50, minHeight: 50, idealHeight: 50, maxHeight: 50, alignment: .center)
                                .background(selectNum == num ? .accent : .blue)
                                .clipShape(.circle)
                        }
                        .buttonStyle(.plain)
                    }
                }
            }
            Section("后区") {
                LazyHGrid(rows: columns, spacing: 15) {
                    ForEach(1..<3) { num in
                        Button {
                            selectNum = num + 5
                        } label: {
                            Text("\(num)")
                                .font(.title)
                                .foregroundStyle(.white)
                                .frame(minWidth: 50, idealWidth: 50, maxWidth: 50, minHeight: 50, idealHeight: 50, maxHeight: 50, alignment: .center)
                                .background((selectNum - 5) == num ? .accent : .blue)
                                .clipShape(.circle)
                        }
                        .buttonStyle(.plain)
                    }
                }
            }
            
            Section("概述") {
                Text(calculateStr)
            }
        }
        .navigationTitle("位置概述")
        .navigationBarTitleDisplayMode(.inline)
    }
}

#Preview {
    MainPositionView(pathStore: .init())
}

extension MainPositionView {
    var calculateStr: String {
        if let lott = lottery {
            switch selectNum {
            case 1:
                let str = "数字1出现次数:\(lott.zStatistic.front1.no01)次\n" +
                          "数字2出现次数:\(lott.zStatistic.front1.no02)次\n" +
                          "数字3出现次数:\(lott.zStatistic.front1.no03)次\n"
                return str
            case 2:
                return ""
            case 3:
                return ""
            case 4:
                return ""
            case 5:
                return ""
            case 6:
                return ""
            case 7:
                return ""
            default:
                return "暂无"
            }
        }else {
            return "暂无"
        }
    }
}

class MainPositionPath: PathName {
    
}
